package reduce.fz.com.reduce.activity;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import de.greenrobot.event.EventBus;
import reduce.fz.com.reduce.R;
import reduce.fz.com.reduce.bean.SocietyNotice;
import reduce.fz.com.reduce.event.SocietyNoticeEvent;
import reduce.fz.com.reduce.fragment.SocietyMemberRankFragment;
import reduce.fz.com.reduce.fragment.SocietyNoticeFragment;

public class SocietyNoticeActivity extends BaseToolBarActivity {

    //社团id
    private Long sid;
    //社团fragment
    private SocietyNoticeFragment fragment;
    //发布按钮
    public TextView mPub;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_society_notice);
        setToolbarTitle("社团公告");
        EventBus.getDefault().register(this);
        sid = getIntent().getLongExtra("sid", 0l);
        mPub = setRightBtn("发布");
        mPub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                forward();

            }
        });
        attachFragment();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    public void onEvent(SocietyNoticeEvent event) {
        fragment.addFrist(event.societyNotice);

    }


    public void forward() {
        Intent intent = new Intent(this, PubNoticeActivity.class);
        intent.putExtra("sid", sid);
        startActivity(intent);
    }


    @Override
    public void initWidget() {

    }

    @Override
    public void initListener() {

    }

    /**
     *
     */
    public void attachFragment() {
        fragment = SocietyNoticeFragment.create(sid);
        getSupportFragmentManager().beginTransaction().replace(R.id.main_container, fragment).commit();
    }
}
